<template>
    <view>
        <!--标题和返回-->
		<cu-custom :bgColor="NavBarColor" isBack :backRouterName="backRouteName">
			<block slot="backText">返回</block>
			<block slot="content">微震实时</block>
		</cu-custom>
		 <!--表单区域-->
		<view>
			<form>
              <view class="cu-form-group">
                <view class="flex align-center">
                  <view class="title"><text space="ensp">事件编码：</text></view>
                  <input  placeholder="请输入事件编码" v-model="model.eventCode"/>
                </view>
              </view>
              <view class="cu-form-group">
                <view class="flex align-center">
                  <view class="title"><text space="ensp">震源坐标 X：</text></view>
                  <input type="number" placeholder="请输入震源坐标 X" v-model="model.coordinateX"/>
                </view>
              </view>
              <view class="cu-form-group">
                <view class="flex align-center">
                  <view class="title"><text space="ensp">震源坐标 Y：</text></view>
                  <input type="number" placeholder="请输入震源坐标 Y" v-model="model.coordinateY"/>
                </view>
              </view>
              <view class="cu-form-group">
                <view class="flex align-center">
                  <view class="title"><text space="ensp">震源坐标 Z：</text></view>
                  <input type="number" placeholder="请输入震源坐标 Z" v-model="model.coordinateZ"/>
                </view>
              </view>
              <view class="cu-form-group">
                <view class="flex align-center">
                  <view class="title"><text space="ensp">震源能量：</text></view>
                  <input type="number" placeholder="请输入震源能量" v-model="model.seismicEnergy"/>
                </view>
              </view>
              <view class="cu-form-group">
                <view class="flex align-center">
                  <view class="title"><text space="ensp">震源震级：</text></view>
                  <input type="number" placeholder="请输入震源震级" v-model="model.magnitude"/>
                </view>
              </view>
              <view class="cu-form-group">
                <view class="flex align-center">
                  <view class="title"><text space="ensp">微震所属地层：</text></view>
                  <input  placeholder="请输入微震所属地层" v-model="model.microseismicStratum"/>
                </view>
              </view>
              <view class="cu-form-group">
                <view class="flex align-center">
                  <view class="title"><text space="ensp">最大振幅：</text></view>
                  <input type="number" placeholder="请输入最大振幅" v-model="model.maxAmplitude"/>
                </view>
              </view>
              <view class="cu-form-group">
                <view class="flex align-center">
                  <view class="title"><text space="ensp">平均振幅：</text></view>
                  <input type="number" placeholder="请输入平均振幅" v-model="model.averageAmplitude"/>
                </view>
              </view>
              <view class="cu-form-group">
                <view class="flex align-center">
                  <view class="title"><text space="ensp">微震事件波形主频：</text></view>
                  <input type="number" placeholder="请输入微震事件波形主频" v-model="model.microseismicFrequency"/>
                </view>
              </view>
              <my-date label="发生时间：" v-model="model.occurredTime" placeholder="请输入发生时间"></my-date>
              <view class="cu-form-group">
                <view class="flex align-center">
                  <view class="title"><text space="ensp">事件分析结论：</text></view>
                  <input  placeholder="请输入事件分析结论" v-model="model.analysisConclusion"/>
                </view>
              </view>
              <view class="cu-form-group">
                <view class="flex align-center">
                  <view class="title"><text space="ensp"> 煤矿编码：</text></view>
                  <input  placeholder="请输入 煤矿编码" v-model="model.stationMine"/>
                </view>
              </view>
              <view class="cu-form-group">
                <view class="flex align-center">
                  <view class="title"><text space="ensp">测点状态 ：</text></view>
                  <input  placeholder="请输入测点状态 " v-model="model.stationStatus"/>
                </view>
              </view>
              <view class="cu-form-group">
                <view class="flex align-center">
                  <view class="title"><text space="ensp">测点编码：</text></view>
                  <input  placeholder="请输入测点编码" v-model="model.stationCode"/>
                </view>
              </view>
				<view class="padding">
					<button class="cu-btn block bg-blue margin-tb-sm lg" @click="onSubmit">
						<text v-if="loading" class="cuIcon-loading2 cuIconfont-spin"></text>提交
					</button>
				</view>
			</form>
		</view>
    </view>
</template>

<script>
    import myDate from '@/components/my-componets/my-date.vue'

    export default {
        name: "WzcdssForm",
        components:{ myDate },
        props:{
          formData:{
              type:Object,
              default:()=>{},
              required:false
          }
        },
        data(){
            return {
				CustomBar: this.CustomBar,
				NavBarColor: this.NavBarColor,
				loading:false,
                model: {},
                backRouteName:'index',
                url: {
                  queryById: "/hydrology/wzcdss/queryById",
                  add: "/hydrology/wzcdss/add",
                  edit: "/hydrology/wzcdss/edit",
                },
            }
        },
        created(){
             this.initFormData();
        },
        methods:{
           initFormData(){
               if(this.formData){
                    let dataId = this.formData.dataId;
                    this.$http.get(this.url.queryById,{params:{id:dataId}}).then((res)=>{
                        if(res.data.success){
                            console.log("表单数据",res);
                            this.model = res.data.result;
                        }
                    })
                }
            },
            onSubmit() {
                let myForm = {...this.model};
                this.loading = true;
                let url = myForm.id?this.url.edit:this.url.add;
				this.$http.post(url,myForm).then(res=>{
				   console.log("res",res)
				   this.loading = false
				   this.$Router.push({name:this.backRouteName})
				}).catch(()=>{
					this.loading = false
				});
            }
        }
    }
</script>
